
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/28/2011 14:20:17
-- Generated from EDMX file: C:\Users\henry\Desktop\GeoFinder.Service\GeoFinder.Service\GeoFinder.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [DBGeoFinder];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_WhiteList_GeoFinderClient]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WhiteList] DROP CONSTRAINT [FK_WhiteList_GeoFinderClient];
GO
IF OBJECT_ID(N'[dbo].[FK_WhiteList_GeoFinderClient1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WhiteList] DROP CONSTRAINT [FK_WhiteList_GeoFinderClient1];
GO
IF OBJECT_ID(N'[dbo].[FK_BlackList_GeoFinderClient]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BlackList] DROP CONSTRAINT [FK_BlackList_GeoFinderClient];
GO
IF OBJECT_ID(N'[dbo].[FK_BlackList_GeoFinderClient1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BlackList] DROP CONSTRAINT [FK_BlackList_GeoFinderClient1];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[GeoFinderClients]', 'U') IS NOT NULL
    DROP TABLE [dbo].[GeoFinderClients];
GO
IF OBJECT_ID(N'[dbo].[WhiteList]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WhiteList];
GO
IF OBJECT_ID(N'[dbo].[BlackList]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BlackList];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'GeoFinderClients'
CREATE TABLE [dbo].[GeoFinderClients] (
    [EmailHASH] bigint  NOT NULL,
    [FacebookID] bigint  NOT NULL,
    [PushURI] nvarchar(max)  NULL,
    [IsConnected] bit  NOT NULL,
    [TileEnabled] bit  NOT NULL,
    [ToastEnabled] bit  NOT NULL,
    [RawEnabled] bit  NOT NULL,
    [PositionGPS] nvarchar(max)  NULL,
    [IsPushEnable] bit  NOT NULL,
    [SearchingArea] int  NOT NULL
);
GO

-- Creating table 'WhiteList'
CREATE TABLE [dbo].[WhiteList] (
    [ToWhite_EmailHASH] bigint  NOT NULL,
    [FromWhite_EmailHASH] bigint  NOT NULL
);
GO

-- Creating table 'BlackList'
CREATE TABLE [dbo].[BlackList] (
    [ToBlack_EmailHASH] bigint  NOT NULL,
    [FromBlack_EmailHASH] bigint  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [EmailHASH] in table 'GeoFinderClients'
ALTER TABLE [dbo].[GeoFinderClients]
ADD CONSTRAINT [PK_GeoFinderClients]
    PRIMARY KEY CLUSTERED ([EmailHASH] ASC);
GO

-- Creating primary key on [ToWhite_EmailHASH], [FromWhite_EmailHASH] in table 'WhiteList'
ALTER TABLE [dbo].[WhiteList]
ADD CONSTRAINT [PK_WhiteList]
    PRIMARY KEY NONCLUSTERED ([ToWhite_EmailHASH], [FromWhite_EmailHASH] ASC);
GO

-- Creating primary key on [ToBlack_EmailHASH], [FromBlack_EmailHASH] in table 'BlackList'
ALTER TABLE [dbo].[BlackList]
ADD CONSTRAINT [PK_BlackList]
    PRIMARY KEY NONCLUSTERED ([ToBlack_EmailHASH], [FromBlack_EmailHASH] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [ToWhite_EmailHASH] in table 'WhiteList'
ALTER TABLE [dbo].[WhiteList]
ADD CONSTRAINT [FK_WhiteList_GeoFinderClient]
    FOREIGN KEY ([ToWhite_EmailHASH])
    REFERENCES [dbo].[GeoFinderClients]
        ([EmailHASH])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [FromWhite_EmailHASH] in table 'WhiteList'
ALTER TABLE [dbo].[WhiteList]
ADD CONSTRAINT [FK_WhiteList_GeoFinderClient1]
    FOREIGN KEY ([FromWhite_EmailHASH])
    REFERENCES [dbo].[GeoFinderClients]
        ([EmailHASH])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WhiteList_GeoFinderClient1'
CREATE INDEX [IX_FK_WhiteList_GeoFinderClient1]
ON [dbo].[WhiteList]
    ([FromWhite_EmailHASH]);
GO

-- Creating foreign key on [ToBlack_EmailHASH] in table 'BlackList'
ALTER TABLE [dbo].[BlackList]
ADD CONSTRAINT [FK_BlackList_GeoFinderClient]
    FOREIGN KEY ([ToBlack_EmailHASH])
    REFERENCES [dbo].[GeoFinderClients]
        ([EmailHASH])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [FromBlack_EmailHASH] in table 'BlackList'
ALTER TABLE [dbo].[BlackList]
ADD CONSTRAINT [FK_BlackList_GeoFinderClient1]
    FOREIGN KEY ([FromBlack_EmailHASH])
    REFERENCES [dbo].[GeoFinderClients]
        ([EmailHASH])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BlackList_GeoFinderClient1'
CREATE INDEX [IX_FK_BlackList_GeoFinderClient1]
ON [dbo].[BlackList]
    ([FromBlack_EmailHASH]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------